﻿using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using WhaleAccount.Contracts.Services;
using WhaleAccount.Contracts.ViewModels;
using Type = WhaleAccount.Models.Type;

namespace WhaleAccount.ViewModels;
public class TypesViewModel : ObservableRecipient, INavigationAware
{
    private readonly ITypeService _typeService;

    public ObservableCollection<Type> TypeList
    {
        get; set;
    }

    public TypesViewModel()
    {
        _typeService = App.GetService<ITypeService>();

        TypeList = new ObservableCollection<Type>();
    }

    public void OnNavigatedFrom()
    {
    }
    public void OnNavigatedTo(object parameter)
    {
        LoadData();
    }

    private async void LoadData()
    {
        var types = await _typeService.GetTypeListAsync();
        foreach (var type in types)
        {
            TypeList.Add(type);
        }
    }
}
